<!DOCTYPE html>

<html lang="en" xmlns:x="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Editor</title>
    <link rel="stylesheet" href="styles.css" type="text/css" media="screen" charset="utf-8">
</head>
<body >
<!-- <vbox style='width:100%;height:100%'>
	<div id="filter">
		<input/>
	</div>
    <vbox flex=1>
	<vbox style='position:relative'>
		<div id="editor">
			<div id="toggleGutter" onclick="toggleGutter();"></div>
		</div>
	</vbox>
	</vbox>class='boxfix'
</vbox> -->

<vbox class="box">
  	<div id="filter">
		<x:textbox/>
	</div>
	<hbox flex='1'>
		<div style="background: none repeat scroll 0pt 0pt rosyBrown; -moz-box-flex: 1; position: relative; overflow: hidden;">
			<div id="editor">
				<div id="toggleGutter" onclick="toggleGutter();"></div>
			</div>
		</div>
	</hbox>
  <div>trois</div>
</vbox>

<style>
.box {
    -moz-box-orient: vertical;
    border: 1px solid #555555;
    display: -moz-box;
    font-size: 14px;
    height: 100%;
    width: 100%;
    position: relative;
}

.boxfix {
	-moz-box-flex: 1;
    -moz-box-align: stretch;
    -moz-box-pack: center;
    background: none repeat scroll 0 0 #CCFFCC;
    display: -moz-box;
    height: auto;
    position: relative;
    width: auto;
}
[flex]{-moz-box-flex: 1;}
hbox{display:-moz-box;}
</style>










    <script type="text/javascript">
//add stub console since ace calls console.error
if(!window.console){
	console={__noSuchFunction__: function(){}};
}

function transformPath(path){
	var aceRoot = '../ace/build/src/'
	var sub = 'ace/theme/'
	if(path.indexOf(sub)==0){
		return aceRoot + 'theme-' + path.substr(sub.length) + '.js'
	}
	var sub = 'ace/keyboard/keybinding/'
	if(path.indexOf(sub)==0){
		return aceRoot + 'keybinding-' + path.substr(sub.length) + '.js'
	}
	var sub = 'ace/mode/'
	if(path.indexOf(sub)==0){
		return aceRoot + 'mode-' + path.substr(sub.length) + '.js'
	}
	var sub = 'fbace/'
	if(path.indexOf(sub)==0){
		return path.substr(sub.length) + '.js'
	}
	return aceRoot + path + '.js'	
}

require = loadScripts = function(deps, callback, lastUrl){
	console.log(deps)
	if(typeof deps == 'string')//this happens when module's path is wrong
		return;
		
	var url = deps.shift()
	if(!url)
		return callback&&callback(require(lastUrl))
	
	
	var script = document.createElementNS('http://www.w3.org/1999/xhtml', "script")
	script.type = "text/javascript";	  
	script.onload = function(){
		loadScripts(deps, callback, url)
	}
   
	script.src = transformPath(url);
	document.documentElement.appendChild(script);
	
	//var t = makeReq(script.src)
	console.log(script.src)
	/*eval(t)*/
	//script.onload()
}

function makeReq(href) {
    var req = new XMLHttpRequest;
    req.overrideMimeType("text/plain");
    req.open("GET", href, false);
    try {
        req.send(null);
    } catch (e) {
    }
    return req.responseText;
}

//*******************************************************************************************
//mini require from ace doesn't work :(
var _define = function(module, deps, payload) {
    if (arguments.length == 2)
        payload = deps;

	if (typeof module !== 'string') {
        if (_define.original)
            _define.original.apply(window, arguments);
        else 
            console.error('dropping module because define wasn\'t a string.');       
        
		return;
    }
        
    define.modules[module] = payload;
};

_define.modules = {};    
if (window.define)
    _define.original = window.define;
window.define = _define;

var _require = function(module, callback) {
    if (Object.prototype.toString.call(module) === "[object Array]") {
        var params = [];
        for (var i = 0, l = module.length; i < l; ++i) {
            var dep = lookup(module[i]);
            if (!dep && _require.original)
                return _require.original.apply(window, arguments);
            params.push(dep);
        }
        if (callback) {
            callback.apply(null, params);
        }
    }
    else if (typeof module === 'string') {
        var payload = lookup(module);
        if (!payload && _require.original)
            return _require.original.apply(window, arguments);
        
        if (callback) {
            callback();
        }
    
        return payload;
    }
    else {
        //if (_require.original)
         //   return _require.original.apply(window, arguments);
		 console.log(arguments)
    }
};

if (window.require)
    _require.original = window.require;
    
window.require = _require;
require.packaged = true;

var lookup = function(moduleName) {
    var module = define.modules[moduleName];
    if (module == null) {
        //console.error('Missing module: ' + moduleName);
        return null;
    }

    if (typeof module === 'function') {
        var exports = {};
        module(require, exports, { id: moduleName, uri: '' });
        // cache the resulting module object for next time
        define.modules[moduleName] = exports;
        return exports;
    }

    return module;
};
//*********************************************************************************************

var onLaunch
var startAce = function(callback, options) {
	if(onLaunch){
		onLaunch = onLaunch || callback
		return
	}
	onLaunch = callback || 'called';
	var rootDeps = ['ace-uncompressed', "ace/mode/javascript", "ace/mode/css", "ace/mode/xml", "ace/mode/html", "fbace/startup"];
	if(!options)
		options = {};
	//"ace/theme/textmate" is built into ace.js so there's no need to load that
	if(!options.theme)
		options.theme = "ace/theme/textmate";
	else if(options.theme != "ace/theme/textmate")
		rootDeps.push(options.theme);

	require(rootDeps, function() {
		var catalog = require("pilot/plugin_manager").catalog;
		catalog.registerPlugins([ "pilot/index" ]).then(function() {
			var env = require("pilot/environment").create();
			catalog.startupPlugins({ env: env }).then(function() {
				require("fbace/startup").launch(env, options);
			}).then(callback);
		});
	});
};

startAce(null,{})
</script>

</body>
</html>
